const Post = require('../model/Post')
const { Op } = require('sequelize')

// 添加一个职位数据
exports.addPost = async function (data) {
    const res = await Post.create(data)
    console.log(res)
}

// 添加一组职位数据
exports.addPosts = async function (data) {
    const res = await Post.bulkCreate(data)
    console.log(res)
}
// 更新一个职位
exports.updatePosts = async function (id, data) {
    const res = await Post.update(data, {
        where: {
            id
        }
    })
    console.log(res)
}
// 删除一个职位
exports.deletePost = async function (id) {
    const res = await Post.destroy({
        where: id
    })
    console.log(res)
}
// 查询职位
exports.selectPost = async function (condition = {}) {
    const where = {}
    if (condition.name) {
        where.name = {
            [Op.substring]: condition.name
        }
    }
    const res = await Post.findAll({
        attributes: ['id', ['name', '职位']],
        where
    })
    console.log(JSON.stringify(res))
    return JSON.stringify(res)
}